// 路由配置信息
import Vue from 'vue'
import VueRouter from 'vue-router'
//引入路由组件
// import Home from '@/pages/Home'
import Search from '@/pages/Search'
import Register from '@/pages/Register'
import Login from '@/pages/Login'
import Detail from '@/pages/Detail'
import AddCartSuccess from '@/pages/AddCartSuccess'
import ShopCart from '@/pages/ShopCart'
import Trade from '@/pages/Trade'
import Pay from '@/pages/Pay'
import PaySuccess from '@/pages/PaySuccess'
import Center from '@/pages/Center'
// 引入二级路由组件
import myOrder from '@/pages/Center/myOrder'
import GroupOrder from '@/pages/Center/groupOrder'
Vue.use(VueRouter);
// 路由懒加载
const foo = () => {
    return import("@/pages/Home")
}
export default [
    {
        path: "/center",
        component: Center,
        meta: { show: true },
        // 二级路由组件
        children: [
            // 二级路由不用写/
            {
                path: "myOrder",
                component: myOrder
            },
            {
                path: "grouporder",
                component: GroupOrder
            },
            // 重定向,跳转到二级路由组件默认显示这个组件
            {
                path: '/center',
                redirect: '/center/myorder'
            }
        ]
    },
    {
        path: "/paysuccess",
        component: PaySuccess,
        meta: { show: true }
    },
    {
        path: "/pay",
        component: Pay,
        meta: { show: true },
        // pay的独享守卫
        beforeEnter: (to, from, next) => {
            // 如果是从交易页面来的,放行
            if (from.path == "/trade") {
                next();
            } else {
                // 不是从交易页面来的,从哪来回哪去
                next(false)
            }
        }
    },
    {
        path: "/trade",
        component: Trade,
        meta: { show: true },
        // trade路由独享守卫
        beforeEnter: (to, from, next) => {
            // 如果是从购物车页面来的,就放行
            if (from.path == "/shopcart") {
                next()
            } else {
                // 如果是从其他页面来的,从哪里来回哪去(from地址)
                next(false);
            }
        }
    },
    {
        path: "/shopcart",
        component: ShopCart,
        meta: { show: true }
    },
    {
        // 配置addcartsuccess路径
        path: "/addcartsuccess",
        component: AddCartSuccess,
        name: 'addcartsuccess',
        // meta是用来显示footer
        meta: { show: true }
    },
    {
        path: "/detail/:skuid",
        component: Detail,
        meta: { show: true }
    },
    {
        path: "/home",
        component: (foo),
        meta: { show: true }
    }
    ,
    {
        name: 'search',
        path: "/search/:keyword?",
        component: Search,
        meta: { show: true }
    }
    ,
    {
        path: "/Register",
        component: Register,
        meta: { show: false }
    }
    ,
    {
        path: "/Login",
        component: Login,
        meta: { show: false }
    }
    ,

    //项目运行后,立马访问首页
    {
        path: '*',
        redirect: "/home"
    }
]


